package com.liujun.spring4.demo.aop.application.property.outerconfig;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.HashMap;
import java.util.Map;

/**
 * @author liujun
 * @version 0.0.1
 * @date 2018/09/06
 */
public class DatabaseProcess {

  public static final DatabaseProcess INSTANCE = new DatabaseProcess();


  private static final String QUERY_SQL = "select cfgName,cfgValue from sysconfig";

  public Map<String, String> getConfig(Connection conn) {
    Map<String, String> rs = new HashMap<>();

    try {
      Statement statement = conn.createStatement();
      ResultSet rsSet = statement.executeQuery(QUERY_SQL);

      while (rsSet.next()) {
        String key = rsSet.getString("cfgName");
        String value = rsSet.getString("cfgValue");
        rs.put(key, value);
      }
    } catch (SQLException e) {
      e.printStackTrace();
    } finally {
      if (null != conn) {
        try {
          conn.close();
        } catch (SQLException e) {
          e.printStackTrace();
        }
      }
    }

    return rs;
  }
}
